package ru.mirent.app.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import ru.mirent.schemegenerator.Part;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Aspect
public class SchemeAspect {
    public static List<Part> partList = new ArrayList<>();

    @Before("execution(* *(..))")
    public void beforeMethod(JoinPoint joinPoint) {
        String className = ((MethodSignature) joinPoint.getSignature()).getMethod().getDeclaringClass().getName();
        String methodName = ((MethodSignature) joinPoint.getSignature()).getMethod().getName();
        Class[] params = ((MethodSignature) joinPoint.getSignature()).getParameterTypes();

        if (!className.contains("equals")) {
            partList.add(new Part(className, methodName, Arrays.asList(params)));
        }

        System.out.println(">>>> " + className + " - " + methodName);
    }
}
